package lec04.pm.gm.v3;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;

class MyCmp implements Comparator<Point>{

	@Override
	public int compare(Point o1, Point o2) {
		int dx=o1.x-o2.x;
		if(dx!=0)return dx;
		return o1.y-o2.y;
	}
	
}
public class Point {
	private static final int RAND_RANGE = 100;

	public static void main(String[] args) {
		Random random = new Random();
		Point[] points = new Point[100];
		for (int i = 0; i < points.length; i++) {
			Point p = new Point();
			p.setX(random.nextInt(RAND_RANGE));
			p.setY(random.nextInt(RAND_RANGE));
			points[i]=p;
		}
		for (Point point : points)
			System.out.println(point);
		MyCmp cmp=new MyCmp();
		Arrays.sort(points,cmp);
		System.out.println("After sorted:");
		for (Point point : points)
			System.out.println(point);

	}
	@Override
	public String toString() {
		return String.format("(%d, %d)",x,y);
	}
	public void setY(int n) {
		this.y=n;
		
	}
	public void setX(int n) {
		this.x=n;
		
	}
	protected int x;
	protected int y;
	
	
	
	
}
